﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using ZOIL.DataModel;

namespace ZOIL.DataBackend
{
    public abstract class CollectionConnectionBase : ICollectionConnection
    {
        #region Implementation of ICollectionConnection

        public abstract string FriendlyName { get; }

        public abstract Bitmap Icon { get; }

        public abstract IPersistableCollection Connect(Dictionary<string, object> parameters);

        public IPersistableCollection ConnectAndSetAsDefaultCollection(Dictionary<string, object> parameters)
        {
            IPersistableCollection coll;
            try
            {
                coll = Connect(parameters);
            }
            catch (Exception e)
            {
                throw new Exception("Could not connect to data backend", e);
            }

            DatabaseCollection.Collection = coll;
            return coll;
        }

        public abstract IList<T> CreateList<T>();
        public abstract ObservableCollection<T> CreateObservableCollection<T>();

        public abstract bool CanStartLocalDatabase();
        public abstract void StartLocalDatabase(Dictionary<string, object> parameters);

        #endregion

        public abstract void Dispose();
    }
}